package top.lvjp.designMode;

/** 产品接口 */
interface Shape1 {
    void draw();
}
interface Color1 {
    void fill();
}

/** 实现接口的实体类 */
class Rectangle1 implements Shape1 {
    @Override
    public void draw() {
        System.out.println("-----Rectangle--------");
    }
}
class Circle1 implements Shape1 {
    @Override
    public void draw() {
        System.out.println("-----Circle-----");
    }
}

class Red implements Color1 {
    @Override
    public void fill() {
        System.out.println("---Red---");
    }
}
class Green implements Color1 {
    @Override
    public void fill() {
        System.out.println("---Green---");
    }
}

/** 创建抽象工厂类 */
abstract class AbstractFactory {
    public abstract Color1 getColor();
    public abstract Shape1 getShape() ;
}

/**  AbstractFactory 的子类,具体工厂*/
class RedCircleFactory extends AbstractFactory {
    @Override
    public Shape1 getShape(){
        return new Circle1();
    }
    @Override
    public Color1 getColor() {
        return new Red();
    }
}
class GreenRectangleFactory extends AbstractFactory {
    @Override
    public Shape1 getShape(){
        return new Rectangle1();
    }
    @Override
    public Color1 getColor() {
        return new Green();
    }
}

/** 使用工厂, 创建一个红色的圈 */
public class AbstractFactoryTest {
    public static void main(String[] args) {
        AbstractFactory factory = new RedCircleFactory();
        Color1 color1 = factory.getColor();
        color1.fill();
        Shape1 shape1 = factory.getShape();
        shape1.draw();
    }
}